package com.agou.ssh.core.db;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class TestDBUtil {

	public static void main(String[] args) {
		TestDBUtil t = new TestDBUtil();
		try {
			t.test();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void test() throws Exception{
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		StringBuilder sbSql = new StringBuilder();
		sbSql.append("select t from TSAdminUser t ");
		sbSql.append(" where t.userLoginId = ?");
		Query query = session.createQuery(sbSql.toString());
		query.setParameter(0, "admin");
		// 对象查询条件
		@SuppressWarnings("unchecked")
		List<Object> reList = query.list();
		System.out.println(reList);
		session.close();
		//sessionFactory.close();
		
		sessionFactory = HibernateUtil.getSessionFactory();
		session = sessionFactory.openSession();
		sbSql = new StringBuilder();
		sbSql.append("select t from TSAdminUser t ");
		sbSql.append(" where t.userLoginId = ?");
		query = session.createQuery(sbSql.toString());
		query.setParameter(0, "admin");
		// 对象查询条件
		System.out.println(query.list());
		session.close();
		sessionFactory.close();
		
	}

}
